<template>
  <a-tree-select
    :treeData="data"
    :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
    :placeholder="placeholder || $t('m.eform.formDesign.label.qing-xuan-ze-suo-shu-ying-yong')"
    :allowClear="allowClear"
    treeDefaultExpandAll
    v-model="selectValue"
    :disabled="disabled"
    @change="onChange"
  >
  </a-tree-select>
</template>

<script>

  import {getAction} from '@/api/manage';
  import YchConstant from "@/api/YchConstant";

  export default {
    name: "GroupIdTag",
    props: {
      value: {
        type: String,
        default: null
      },
      placeholder: {
        type: String,
      },
      disabled: {
        type: Boolean,
        default: false
      },
      allowClear: {
        type: Boolean,
        default: true
      }
    },
    data() {
      return {
        data: [],
        url: {
          getGroupTree: YchConstant.PREFIX_EFORM + "/manage/actAppGroup/getGroupTree"
        },
        selectValue: undefined,
      }
    },
    created() {
      getAction(this.url.getGroupTree, {}).then((res) => {
        if (res.success) {
          this.data = res.result;
        } else {
          this.messageUtil.warning(res.message)
        }
      });
    },
    watch: {
      value: {
        handler(val) {
          this.selectValue = val || undefined;
        },
        immediate: true
      }
    },
    methods: {
      onChange(value) {
        this.$emit('input', value)
        this.$emit('change', value)
      }
    },
    model: {
      prop: 'value',
      event: 'change'
    }
  }
</script>
